#include <iostream>
#include <cstring>

using namespace std;

const char * mystrstr(const char *str, const char *substr)
{
    size_t i = 0, j = 0;
    size_t len = strlen(str); size_t slen = strlen(substr);

    while((i<len)&&(j<slen))
    {
        if(str[i] == substr[j])
        {
            i++;j++;
        }
        else
        {
            i = i-j;
            j = 0;
            i++;
        }
    }

    if(j == slen) return str+(i-j);
    
    return 0;
}


int main(void)
{
    char str1[31] = "Hello,world!";
    char str2[31] = "llo";
    
    /* test mystrstr */
    const char *p = mystrstr(str1, str2);    

    cout << (void *)p << endl;
    return 0;
}
